<!-- 订单页 -->
<template>
	<view class="order-page">
		<view class="sticky" v-if="technicianStatus">
			<!-- 搜索框 -->
			<view class="search-content">
				<image class="search-img" src="/static/sousuo.png"></image>
				<input placeholder="请搜索订单号" v-model="searchVal" @input="changeInput" @confirm="changeSearch"
					style="width: auto;line-height: 1em; " placeholder-style="font-size:28rpx;color:#A1A1A1;" />
				<image v-if="searchVal" class="icon_close" src="/static/delect.png" @click="close"></image>
			</view>
			<view class="p-fff10">
				<sunui-navbar :items="tabList" lineHeight="70rpx" :isCenter="true" :currentIndex="currentIndex"
					padding="20rpx" :size="90" activeLineBg="#fff" textAlign="center" activeLineWidth="40%"
					activeDirection="center" activeLineHeight="4rpx" bgColor="#fff" :margin="10"
					@change="getChange"></sunui-navbar>
			</view>
			<mescroll-body ref="mescrollRef" :height="windowHeight+'rpx'" @init="mescrollInit" @down="downCallback"
				@up="upCallback" :up="upOption" :down="downOption">
				<view class="card-cls" v-for="(i, j) in list" :key="j" @click="viewOrderDetail(i.id)">
					<view class="flex-between p-bottom30">
						<view v-if="i.status == 1&&i.refundStatus==2">
						     <view class="v-timeout-stauts flex">用户申请退款中</view>

						</view>
						<!-- 倒计时 -->
						<view v-else>
							<block v-if="i.status == 1 && Number(timestamps(i.createdAt)) - currTime > 0">
								<view class="flex-between p-bottom30">
									<view class="v-stauts flex">
										接单时间:
										<sunui-countdown :time="Number(timestamps(i.createdAt)) - currTime" @end="end"
											:timeid="i.id" :showDay="false"></sunui-countdown>
									
									</view>
									<view style="margin-left: 15px;" class="stauts-clsTime flex" @click.stop="timeOpen(i)">
										修改预约时间
									
									</view>
								</view>
							</block>
							<!-- 已超时 -->
							<block v-else-if="i.status == 1 && Number(timestamps(i.createdAt)) - currTime <= 0">
								<view class="v-timeout-stauts flex">已超时</view>
							</block>
							<!-- 已接单后的状态 -->
							<block v-else>
								<view class="flex-align-center order-num">
									<text class="font-overflow"
										style="max-width: 430rpx;">订单编号：{{ i.orderNumber }}</text>
									<view @click.stop="paste(i.orderNumber)">复制</view>
								</view>
							</block>
						</view>

						<!-- status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款 -->
						<text v-if="i.status == 1&&i.refundStatus==2" class="stauts-cls flex">退款中</text>
						<text v-else class="stauts-cls flex">{{ orderStatusFn(i.status) }}</text>

					</view>
					<view class="flex-align-center">
						<div v-if="i.fatherOrderNumber" class="addClockImg">
							<image class="order-img" :src="i.packageList.rotationChart"></image>
							<view class="addClock">
								加钟
							</view>
						</div>
						<div v-else>
							<image class="order-img" :src="i.packageList.rotationChart"></image>
						</div>
						<view class="flex-columns flex1">
							<view class="flex-start">
								<view class="color333 font32">{{ i.packageList.tradeName }}</view>
								<!-- <uni-tooltip>
									<view @click.stop="toolTip" v-if="i.remark" style="margin-left: 15rpx;" size="mini">订单备注</view>
									<template v-slot:content>
										<view class="uni-stat-tooltip">
											{{i.remark?i.remark:'暂无订单备注'}}
										</view>
									</template>
								</uni-tooltip> -->
							</view>
							<view :class="i.transferOrder ? 'flex-between' : 'flex-align-center'">
								<view class="appointment-time">预约时间：{{i.serviceStartTime}}
								</view>
								<!-- 转单订单——拨打电话功能 -->
								<!-- <view class="call-cls flex" v-if="i.transferOrder"
									@click="callPhone(i.technician.mobile)">
									<image mode="heightFix" src="/static/technician/call-icon.png"></image>
								</view> -->
							</view>
							<view class="flex-align-center">
								<view v-if="i.orderList.length" class="color333 font32 bold">
									￥{{ disbursementsFn(Number(  i.disbursements),i.orderList )}}</view>
								<view v-else class="color333 font32 bold">
									￥{{ i.fatherOrderNumber?i.plusClockPrice:i.disbursements }}</view>
								<text class="segmentation">|</text>
								<view class="flex-align-center time-icon">
									<text class="iconfont icon-shijian"></text>
									<view v-if="i.orderList.length">
										{{ serviceTimeFn(Number(i.packageList.serviceTime ),i.orderList)}}分钟
									</view>
									<view v-else>{{ i.packageList.serviceTime }}分钟</view>
								</view>



							</view>

						</view>
						<view>
							<view v-if="i.orderList.length">
								数量x{{i.orderList.length+1}}
							</view>
							<view v-else>
								数量x1
							</view>
						</view>
					</view>
					<!-- i.transferOrder 存在则是转单 -->
					<view class="flex-align-center transfer-cls" v-if="i.transferOrder">
						<image src="/static/avater.png"></image>
						<view>转单同事：{{ i.transferOrder }}</view>
					</view>
					<!-- 分割线 -->
					<view class="dashed-line"></view>
					<view class="flex-between">
						<view class="flex-align-center address-cls">
							<text class="iconfont icon-dingweiweizhi"></text>
							<view class="font-overflow " style="max-width: 500rpx;">
								{{ i.addressManagement.province }}
								<!-- 省 -->
								{{ i.addressManagement.city }}
								<!-- 市 -->
								{{ i.addressManagement.district }}
								<!-- 区 -->
								{{ i.addressManagement.address }}
								<!-- 详细地址 -->
							</view>
						</view>
						<view class="v-navigation flex-align-center" @click.stop="addressFn(i.addressManagement)">
							<!-- 需要目的地经纬度 -->
							导航

							<!-- <image src="/static/navigation.png"></image> -->
						</view>
					</view>
					<view class="flex-between" style="margin-top: 15rpx;">
						<view class="flex-align-center address-cls">
							<text class="iconfont icon-lianxirenxinxi"></text>
							<view class="font-overflow " style="max-width: 500rpx;">
								{{i.addressManagement.consignee}} {{i.addressManagement.mobile}}
							</view>
						</view>
						<view class="v-navigation flex-align-center"
							@click.stop="callIphone(i.addressManagement.mobile)">
							<!-- 需要目的地经纬度 -->

							拨打
							<!-- <image src="/static/navigation.png"></image> -->
						</view>
					</view>

					<!-- <view class="flex-align-center">
					<text class="iconfont icon-shijian"></text>
					<view>永州大道梦想家园A栋1单元2023号</view>
					<view>拨打</view>
				    </view> -->

					<view v-if="i.status == 1 && Number(timestamps(i.createdAt)) - currTime >= 0">
						<view class="flex-around m-top40">
							<!-- status 订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款） -->
							
							<view v-if="!(i.status == 1&&i.refundStatus==2)" class="refuse-order flex" @click.stop="refuseOrders(i)">拒绝</view>

							<!-- transferOrder存在，代表是 “转单技师” 订单，已转技师的单，不可再二次转单 -->
						
							<view v-if="!(i.status == 1&&i.refundStatus==2)" class="refuse-order flex" @click.stop="toTransferOrder(i)"
								>
								我要转单
							</view>
                              <!-- v-if="!i.transferOrder" -->
						
							<view v-if="!(i.status == 1&&i.refundStatus==2)" class="agree-btn flex" :class="i.transferOrder ? 'big-btn' : ''"
								@click.stop="updateOrders(i.id, 2)">同意接单</view>

						</view>
					</view>
					<view v-if="i.status == 2&&!(i.fatherOrderNumber)">
						<view class="service-btn flex" @click.stop="updateOrders(i.id, 3)">开始服务</view>
					</view>
					<view v-if="i.status == 3&&!(i.fatherOrderNumber)">
						<view class="service-btn flex" @click.stop="updateOrders(i.id, 4)">结束服务</view>
					</view>

				</view>
			</mescroll-body>
		</view>
		<view v-else>

		</view>
		<!-- ‘冻结’ 弹框 -->
		<sunui-popup ref="popFreeze">
			<template v-slot:content>
				<view class="v-pop-freeze flex-column">
					<view class="v-title">提示</view>
					<view class="v-content">你的站点已冻结，请联系管理员</view>
				</view>
			</template>
		</sunui-popup>
		<sunui-popup ref="technicianFreeze">
			<template v-slot:content>
				<view class="v-pop-freeze flex-column">
					<view class="v-title">提示</view>
					<view class="v-content">你的员工端被冻结，请联系管理员</view>
				</view>
			</template>
		</sunui-popup>
		<!-- “服务时间” 弹出框 -->
		<sunui-popup ref="timepop">
			<template v-slot:content>
				<view class="v-time-pop">
					<view class="p-bottom30">
						<sunui-navbar :items="dayList" lineHeight="70rpx" :isCenter="true" :currentIndex="daytIndex"
							:size="180" color="#666" activeLineBg="#1890ff" textAlign="center" activeColor="#1890ff"
							activeLineWidth="30%" activeDirection="center" activeLineHeight="6rpx" bgColor="#fff"
							:margin="10" @change="getChangeTime"></sunui-navbar>
					</view>
					<scroll-view :scroll-y="true" style="height: 600rpx;">
						<view class="flex-wrap">
							<block v-for="(i, j) in timeList" :key="j">
								<view class="flex-column time-cls"
									:class="timeIndex == j ? 'sel-time-cls' : i.isDisable == true ? 'none-time-cls' : 'v-time-pop'"
									@click.stop="timeClick(j)">
									<text>{{ i.time.split(' ')[1] }}</text>
									<view class="p-top10">{{ i.isDisable == true ? '不可预约' : '可预约' }}</view>
								</view>
							</block>
						</view>
					</scroll-view>
					<view class="confirm-time flex" @click="timeConfirm">确定</view>
				</view>
			</template>
		</sunui-popup>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapState,
		mapMutations
	} from 'vuex'
	import common from '@/common/js/common.js';
	export default {
		data() {
			return {
				currTime: new Date().getTime(), // 当前时间
				searchVal: '',
				downOption: {
					auto: false
				},
				daytIndex: 0, //自定义索引
				dayList: common.weekDate().dayList,
				// 忙时设置
				busySetList: [],
				selServiceStartTime: '', //选中的，服务开始时间
				serviceStartTime: '', //服务开始时间
				timeIndex: -1, //“服务时间”点击index
				timeList: [{
						time: '00:30',
						isDisable: false
					},
					{
						time: '01:00',
						isDisable: false
					},
					{
						time: '01:30',
						isDisable: false
					},

					{
						time: '02:00',
						isDisable: false
					},
					{
						time: '02:30',
						isDisable: false
					},
					{
						time: '03:00',
						isDisable: false
					},
					{
						time: '03:30',
						isDisable: false
					},

					{
						time: '04:00',
						isDisable: false
					},
					{
						time: '04:30',
						isDisable: false
					},
					{
						time: '05:00',
						isDisable: false
					},
					{
						time: '05:30',
						isDisable: false
					},

					{
						time: '06:00',
						isDisable: false
					},
					{
						time: '06:30',
						isDisable: false
					},
					{
						time: '07:00',
						isDisable: false
					},
					{
						time: '07:30',
						isDisable: false
					},

					// old start
					{
						time: '08:00',
						isDisable: false
					},
					{
						time: '08:30',
						isDisable: false
					},
					{
						time: '09:00',
						isDisable: false
					},
					{
						time: '09:30',
						isDisable: false
					},

					{
						time: '10:00',
						isDisable: false
					},
					{
						time: '10:30',
						isDisable: false
					},
					{
						time: '11:00',
						isDisable: false
					},
					{
						time: '11:30',
						isDisable: false
					},

					{
						time: '12:00',
						isDisable: false
					},
					{
						time: '12:30',
						isDisable: false
					},

					{
						time: '13:00',
						isDisable: false
					},
					{
						time: '13:30',
						isDisable: false
					},

					{
						time: '14:00',
						isDisable: false
					},
					{
						time: '14:30',
						isDisable: false
					},

					{
						time: '15:00',
						isDisable: false
					},
					{
						time: '15:30',
						isDisable: false
					},

					{
						time: '16:00',
						isDisable: false
					},
					{
						time: '16:30',
						isDisable: false
					},

					{
						time: '17:00',
						isDisable: false
					},
					{
						time: '17:30',
						isDisable: false
					},

					{
						time: '18:00',
						isDisable: false
					},
					{
						time: '18:30',
						isDisable: false
					},

					{
						time: '19:00',
						isDisable: false
					},
					{
						time: '19:30',
						isDisable: false
					},

					{
						time: '20:00',
						isDisable: false
					},
					{
						time: '20:30',
						isDisable: false
					},

					{
						time: '21:00',
						isDisable: false
					},
					{
						time: '21:30',
						isDisable: false
					},

					{
						time: '22:00',
						isDisable: false
					},
					{
						time: '22:30',
						isDisable: false
					},
					// old end
					{
						time: '23:00',
						isDisable: false
					},
					{
						time: '23:30',
						isDisable: false
					},

					{
						time: '00:00',
						isDisable: false
					}
				],
				// 上拉配置项
				upOption: {
					auto: false
				},
				// status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款
				tabList: [{
						name: '全部',
						id: '' //null
					},
					{
						name: '新订单',
						id: 1
					},
					{
						name: '待服务',
						id: 2
					},
					{
						name: '进行中',
						id: 3
					},
					{
						name: '已完成',
						id: 4
					},
					{
						name: '退款/已取消',
						id: 5
					}
				],
				currentIndex: 0, //自定义索引
				list: [],
				technicianStatus: false,
				windowHeight: '',
				// 加钟价格
				plusClockPrice: 0,
				// 分钟价格
				serviceTimePrice: 0,
				// 当前订单列表
				currentOrderList: null

			};
		},
		computed: {

			// 日期转13位时间戳
			timestamps: function() {
				return function(day) {
					let timestamps = '';
					/* let time = day.split('T')[0] + ' ' + day.split('T')[1];
						timestamps = new Date(time).getTime(); */
					timestamps = new Date(day).getTime();
					timestamps = timestamps + 3600 * 1000 * 1; // 在下单时间的基础上，加一小时
					// console.log('timestamps======', timestamps);
					return timestamps;
				};
			},
			// 日期转13位时间戳
			// timestamps: function() {
			// 	return function(day) {
			// 		let timestamps = '';
			// 		/* let time = day.split('T')[0] + ' ' + day.split('T')[1];
			// 			timestamps = new Date(time).getTime(); */
			// 		timestamps = new Date(day).getTime();
			// 		// console.log('timestamps======', timestamps);
			// 		return timestamps;
			// 	};
			// },

			serviceTimeFn: function() {
				return function(zhuSum, projectList) {
					let sum = '';
					let fitSum = 0;
					for (let i = 0; i < projectList.length; i++) {

						fitSum += Number(projectList[i].serviceTime);

					}
					console.log('fitSum', fitSum);
					sum = Number(zhuSum) + fitSum;
					console.log(sum)
					return Number(sum);
				};
			},

			disbursementsFn() {
				return function(zhuSum, projectList) {
					let sum = '';
					let fitSum = 0;
					for (let i = 0; i < projectList.length; i++) {

						fitSum += Number(projectList[i].plusClockPrice);

					}
					console.log('fitSum', fitSum);
					sum = Number(zhuSum) + fitSum;
					console.log(sum)
					return Number(sum).toFixed(2);
				};


			},

			// 订单状态
			orderStatusFn: function() {
				return function(status) {

					let orderStatus = '';
					// status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款)
					orderStatus =
						status == 0 ? '待付款' : status == 1 ? '待接单' : status == 2 ? '已接单' : status == 3 ? '服务中' :
						status == 4 ? '已完成' : status == 5 ? '已退款' : '';
					return orderStatus;
				};
			},
			...mapGetters('user', ['taskCenter', 'technicianDetails', 'authorizationInformation']),

		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight * 2 - 104;
				}
			});



		},
		onShow() {
			console.log(common.weekDate().dayList)
			this.handleLogin()
			this.$at.releaseKey('submit');
			this.getSiteDomainID()
			this.getChange(0);
			// this.getAuthorizeInfo(); // 获取当前位置_暂不调用，一直掉用会频繁

			// 取消图标角
			uni.removeTabBarBadge({
				index: 1
			})
			uni.hideTabBarRedDot({
				index: 1
			})

		},
		methods: {
			timeConfirm() {
				if (!this.selServiceStartTime) {
					this.$sun.toast('请选择预约时间');
					return;
				}
				/* 预约时间和服务时间算的不足判断，需要测试 */
				/* const dateObj = new Date(this.selServiceStartTime);
				// console.log("dateObj===",dateObj);
				// 2、在当前时间dateObj变量上加上【服务时长】分钟
				var addMinute = new Date(dateObj.setMinutes(dateObj.getMinutes() + Number(this.projectInfo.serviceTime))); //addMinute: Fri May 22 2020 19:21:37 GMT+0800 (中国标准时间)
				// console.log('addMinute:', addMinute,'this.$sun.newDate',this.$sun.newDate(addMinute))
				// console.log("this.selServiceStartTime",this.selServiceStartTime)
			
				// this.selServiceStartTime 当前预约时间
				// this.$sun.newDate(addMinute) 计算的当前预约结束时间
				// 去筛选 禁用时间,有没有大于当前预约时间 && 小于等于 计算的当前预约结束时间,如果有,代表后面的时间被预定了,用户不能选择
				// console.log('this.busySetList',this.busySetList)
			
				var flag = false; // 初始化标志变量为false
				for (let i = 0; i < this.busySetList.length && !flag; i++) {
					let startTime = this.selServiceStartTime + ':00';
					let endTime = this.$sun.newDate(addMinute);
					let nowTime = this.$sun.dateConversion(this.busySetList[i].service_time);
					if (nowTime > startTime && nowTime <= endTime) {
						console.log('找到了目标元素');
						flag = true; // 当满足条件时将标志变量设置为true，从而提前结束循环
						console.log('已达到要求时间nowTime,startTime,endTime', nowTime, startTime, endTime);
					}
				}
				console.log('退出循环',flag,flag==true);
				if (flag==true) {
					console.log("12333333333")
					this.$sun.toast('预约时间不足,请重选时间');
					return;
				} */

				this.serviceStartTime = '';
				this.serviceStartTime = this.selServiceStartTime;
				this.closeTime();
			},
			// 关闭“服务时间”弹窗
			closeTime() {

				this.$refs.timepop.close();
				this.save()
			},
			async save() {

				let serviceStartTime = this.serviceStartTime + ':00';
				// let serviceStartTime = new Date(serviceStartTime).getTime(); // 日期传13位时间戳
				console.log('serviceStartTime', serviceStartTime);

				const result = await this.$http.put({
					url: this.$api.createUpdate,
					data: {
						// siteId: uni.getStorageSync('siteId'), // 站点id
						// userId: uni.getStorageSync('userId'), //登录用户的id
						// technicianEvaluationId:this.currentOrderList.technicianEvaluationId, //理疗师id
						// packageListId: this.currentOrderList.packageListId, //商品id
						// number: 1, //数量
						id: this.currentOrderList.id,
						// serviceTime: this.currentOrderList.serviceTime, //服务时间/分钟
						serviceStartTime: serviceStartTime, //服务开始时间
						// fatherOrderNumber: '', //加钟交类订单编号
						// plusClockPrice: '', //加钟价格
						// // fareDetails: this.orderNotes, //车费详情
						// remark: '', //订单详情
						// expensesIncurred: '', //出行费用
						// pointsUsed: this.currentOrderList.pointsUsed, //所用积分
						// cardRollId: this.currentOrderList.cardRollId || '', //卡券id
						// deductionAmount: this.currentOrderList.deductionAmount, //抵扣金额
						// disbursements:this.currentOrderList.disbursements, //实付款
						// addressManagementId: this.currentOrderList.addressManagementId, //地址id
						// addressManagements:'',

						// reasonForRejection: '', //驳回原因
						// status: this.currentOrderList.status == 1 ? 1 : 0, //订单状态 (0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款）
						// payMethod: this.currentOrderList.payMethod, //支付方式 1：余额 2：微信
						// payStatus: this.currentOrderList.payStatus == 1 ? 1 : 2 //支付状态 1：已支付 2：未支付

						/* status: 0, //订单状态 (0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款）
						payMethod: 2, //支付方式 1：余额 2：微信
						payStatus: 2 //支付状态 1：已支付 2：未支付 */
					}
				});
				if (result.code == 200) {
					this.$sun.toast('修改预约时间成功')
					this.$nextTick(() => {
						this.mescroll.resetUpScroll();
					});
				} else {
					this.$sun.toast('修改预约时间失败')
				}

			},
			timeClick(index) {
				// this.selServiceStartTime = '';
				let time = '';
				console.log('this.timeList[this.timeIndex]', this.timeList[this.timeIndex], 'this.timeList', this
					.timeList);
				// 可预约状态，才能进入
				if (this.timeList[index].isDisable == false) {
					this.timeIndex = index;
					// let day = this.dayList[this.daytIndex].date;
					// this.serviceStartTime = day + ' ' + time;
					time = this.timeList[this.timeIndex].time;
					this.selServiceStartTime = time;
					console.log('服务时间,this.timeList', this.timeList, 'this.selServiceStartTime', this.selServiceStartTime);
				}
			},
			callIphone(iphone) {
				uni.makePhoneCall({
					phoneNumber: iphone //仅为示例
				});
			},
			// 查询忙时设置 数据回显（公众号使用）
			async getBySelectBusyHourSettings() {
				uni.showLoading({
					title: '加载中'
				});
				console.log('12313=========')
				const result = await this.$http.get({
					url: this.$api.getBySelectBusyHourSetting,
					data: {
						technicianId: Number(wx.getStorageSync('technicianId'))
					}
				});
				if (result.code == 200) {
					console.log('查询忙时设置 数据回显result.', result);
					this.busySetList = result.data;
					this.getTechnicianHourSettings();

				} else {
					this.$sun.toast(result.message);
				}
			},
			// 查询技师已预约时间 数据回显（公众号使用）
			async getTechnicianHourSettings() {
				const result = await this.$http.get({
					url: this.$api.getTechnicianHourSetting,
					data: {
						technicianId: Number(wx.getStorageSync('technicianId'))
					}
				});
				if (result.code == 200) {
					console.log('查询技师已预约时间 数据回显result.', result.data);
					let addList = result.data;
					for (let i = 0; i < addList.length; i++) {
						console.log('addList[i].service_time11', addList[i].service_time);
						let time = addList[i].service_time;
						let date = time.split(' ')[0];
						let hourAll = time.split(' ')[1];

						let hour = hourAll.split(':')[0];
						let min = hourAll.split(':')[1];
						let mis = hourAll.split(':')[2];
						console.log('hour,min,mis', hour, min, mis);
						if (min > '30' && min != '30') {
							min = '30';
						}
						if (min < '30' && min != '00') {
							min = '00';
						}
						let hourAll2 = hour + ':' + min + ':' + mis;

						console.log('hour', hour);
						addList[i].service_time = date + 'T' + hourAll2;
						console.log('addList[i].service_time222', addList[i].service_time);
					}
					this.busySetList = this.busySetList.concat(addList);
					this.getChangeTime(0);
					console.log('查询技师已预约时间 this.busySetList', this.busySetList);
					uni.hideLoading();
				} else {
					this.$sun.toast(result.message);
				}
			},
			// disbursementsFn(orderList){

			// 		this.$nextTick(()=>{
			// 			this.plusClockPrice=0
			// 			orderList.forEach((item)=>{
			// 				this.plusClockPrice=Number(item.plusClockPrice)+Number(this.plusClockPrice)

			// 			})


			// 		})
			//          	return this.plusClockPrice
			// },
			// serviceTimeFn(orderList){

			// 		this.$nextTick(()=>{
			// 			this.serviceTimePrice=0
			// 			orderList.forEach((item)=>{
			// 				this.serviceTimePrice=Number(item.serviceTime)+Number(this.serviceTimePrice)

			// 			})


			// 		})
			// return this.serviceTimePrice
			// },
			// 获取tabList数据
			getChangeTime(index) {
				console.log('index', index);
				this.timeList.map(item => {
					item.isDisable = false;
					console.log('item', item);
					// return{}
				});
				this.daytIndex = index;
				console.log('this.dayList[this.daytIndex]', this.dayList[this.daytIndex], this.dayList[this.daytIndex]
					.date);

				/* 做timeList，中的time，年月日时分秒赋值 。start */
				for (let i = 0; i < this.timeList.length; i++) {
					// console.log('this.timeList[i].time', this.timeList[i].time);
					// console.log('i', this.timeList[i]);
					// 第一次进入，则不需要做分割,并且找不到为空格间隔的
					// 日期字符串中不包含空格，则没有年月日
					if (index == 0 && this.timeList[i].time.indexOf(' ') == -1) {
						this.timeList[i].time = this.dayList[this.daytIndex].date + ' ' + this.timeList[i].time;
					} else {
						this.timeList[i].time = this.dayList[this.daytIndex].date + ' ' + this.timeList[i].time.split(' ')[
							1];
					}
				}
				console.log('aaaaaaaaaathis.timeList', this.timeList);
				/* 做timeList，中的time，年月日时分秒赋值 。end */

				/* 做timelist,如果当天日期超出，则不能被选中 start */
				// index==0 代表当天
				let nextIndex = 0;
				for (let i = 0; i < this.timeList.length; i++) {
					if (index == 0) {
						let oldTime = this.timeList[i].time + ':00';
						if (oldTime < this.$sun.getNowDate()) {
							this.$set(this.timeList[i], 'isDisable', true);
							nextIndex = i;
						}
					}
				}
				// 统一多加半小时预约时间（因此条件判断不需要=）
				// this.$set(this.timeList[nextIndex + 1], 'isDisable', true);
				if (index == 0) {
					// 统一多加半小时预约时间（因此条件判断不需要=）
					this.$set(this.timeList[nextIndex + 1], 'isDisable', true);
					console.log('进入改变isDisable3333333===========', this.timeList[nextIndex + 1]);
				}
				/* end */

				/* 做忙时设置判断，如果时间相同，则将isDisable（禁用）设置为true ——start */
				for (let j = 0; j < this.busySetList.length; j++) {
					for (let i = 0; i < this.timeList.length; i++) {
						let serviceTime = this.busySetList[j].service_time.split('T')[0] + ' ' + this.busySetList[j]
							.service_time.split('T')[1];
						// console.log('serviceTime',serviceTime,'this.timeList[i].time',this.timeList[i].time );
						if (serviceTime == this.timeList[i].time + ':00') {
							console.log('进入改变isDisable===========');
							this.$set(this.timeList[i], 'isDisable', true);
						}
					}
				}
				/* 做忙时设置判断，如果时间相同，则将isDisable（禁用）设置为true ——end */

				console.log('22222222222this.timeList[i]', this.timeList);
				//清空预约时间time start
				this.timeIndex = -1;
				this.selServiceStartTime = '';
				//清空预约时间time end
			},
			viewOrderDetail(id) {
				console.log('123131')
				this.$sun.navGo('/pages/order/technician-detail', {
					id: id
				})
			},
			timeOpen(item) {
				this.getBySelectBusyHourSettings();
				// 当前订单id列表
				this.currentOrderList = item
				this.$refs.timepop.show({
					anim: 'bottom',
					position: 'bottom',
					shadeClose: true, //false使用户不能点击其它关闭页面
					topclose: false
				});
			},
			openFreeze() {
				console.log('进入‘冻结’弹出框');
				this.$refs.popFreeze.show({
					anim: 'center',
					shadeClose: false, //false使用户不能点击其它关闭页面
					topclose: false
				});
			},
			openTechnicianFreeze() {
				console.log('进入‘冻结’弹出框');
				this.$refs.technicianFreeze.show({
					anim: 'center',
					shadeClose: false, //false使用户不能点击其它关闭页面
					topclose: false
				});
			},
			handleLogin() {
				// 如果当前状态被冻结那么不然操作
				if (this.technicianDetails.status == 3) {
					this.openTechnicianFreeze()
				} else {
					this.$refs.technicianFreeze.close()
				}
				if (uni.getStorageSync('userId')) {

					if (this.technicianDetails.authenticationNot !== 3) {
						this.technicianStatus = false
						uni.showModal({
							title: '当前状态',
							content: '当前认证未审核通过无法查看订单',
							success: (res) => {

								if (res.confirm) {
									// 需要箭头函数不然会报错
									this.$sun.navSwitch('/pages/index/index')
									console.log('用户点击确定');
								} else if (res.cancel) {
									this.$sun.navSwitch('/pages/index/index')
									console.log('用户点击取消');
								}

							}
						});
					} else {
						this.technicianStatus = true,
							this.$nextTick(() => {
								this.mescroll.resetUpScroll();
							});
					}

				} else {
					this.$sun.navRe('/pages/login/login');
					// uni.navigateTo({
					// 	url: `/pages/login/login?tap=1`
					// });
					// 不在跳转到登录页面而是直接用弹框来显示
				}
			},

			async getSiteDomainID() {
				const url = this.$api.getSiteDomainName
				const siteDomainName = url.match(/^(?:https?:\/\/)?([^\/]+)/i)[1];
				console.log(siteDomainName)
				// uploadQualificationForm','uploadHealthCertificateForm','uploadAvatarForm','identityAuthenticationForm
				const result = await this.$http.get({
					url: this.$api.getSiteDomainName,
					data: {
						siteDomainName: siteDomainName // 站点域名(传值将https截取)
					}
				});

				if (result.code == 200) {
					// ‘冻结’弹出框

					if (result.data.siteStatus == '1') {
						this.openFreeze()
					} else {
						this.$refs.popFreeze.close()
					}
					this.siteId = result.data.id;

					uni.setStorageSync('siteId', this.siteId)
					console.log('根据站点域名查询站点result.', result);

				} else {
					this.$sun.toast(result.message)
				}
			},

			// 拨打技师电话
			callPhone(phone) {
				this.$sun.phone(phone)
			},
			/* 获取当前经纬度 start */

			//（获取当前位置）
			getAuthorizeInfo() {
				console.log('获取当前位置');
				const that = this;
				uni.authorize({
					scope: 'scope.userLocation',
					success() {
						console.log(11111);
						// 允许授权
						that.getLocations();
					},
					fail() {
						console.log(222222);
						// 拒绝授权
						that.openConfirm();
					}
				});
			},
			//获得地理位置经纬度
			getLocations() {
				console.log('获得地理位置经纬度11');
				wx.getLocation({
					// 将wgs84 改为 gcj02  h5提高精确度
					type: 'gcj02',
					//  geocode: true,   address：地址信息（仅App端支持，需配置geocode为true）
					success: res => {
						this.lat = res.latitude;
						this.lng = res.longitude;
						// 获取当前经纬度  存缓存  在计算差距离的时候 调用
						wx.setStorageSync('lat', this.lat);
						wx.setStorageSync('lng', this.lng);
						console.log('授权成功=====res', res, 'this.lat', this.lat, 'this.lng', this.lng);
						// 调用接口
					},
					fail: res => {
						this.lat = res.latitude;
						this.lng = res.longitude;
						console.log('授权失败res=====', res, 'this.lat', this.lat, 'this.lng', this.lng);
					}
				});
			},
			// 当用户第一次拒绝后再次请求授权
			openConfirm() {
				uni.showModal({
					title: '请求授权当前位置',
					content: '需要获取您的地理位置，请确认授权',
					success: res => {
						// // 调用接口
						this.getLocations();
						if (res.confirm) {
							console.log('请求授权当前位置res.confirm', res);
							// 调用接口
							uni.openSetting(); // 打开地图权限设置
						} else if (res.cancel) {
							uni.showToast({
								title: '你拒绝了授权，无法获得周边信息',
								icon: 'none',
								duration: 10
							});
							this.$sun.toast('定位失败');
						}
					}
				});
			},

			/* 获取当前经纬度 end */

			// 我要转单
			toTransferOrder(item) {
				console.log('我要转单前item========', item);
				this.$sun.navGo('/pages/transfer-order/transfer-order', {
					packageId: item.packageList.id, //套餐id
					siteId: item.siteId, // 站点id
					userId: item.userId, //登录用户的id
					transferOrder: item.technician.id, // 需要转单技师id（old）
					orderId: item.id // 订单id
				});
			},
			getChange(index) {
				this.currentIndex = index;
				this.mescroll.resetUpScroll();
			},

			// 复制订单号
			paste(orderNumber) {
				uni.setClipboardData({
					data: orderNumber
				});
			},
			//监听输入框输入的值
			changeInput(e) {
				this.searchVal = e.detail.value

			},
			//输入键盘的搜索
			changeSearch() {
				this.mescroll.resetUpScroll();
			},
			close() {
				this.searchVal = '';
				this.mescroll.resetUpScroll();
			},

			// 我的订单
			/* async queryOrder() {
				const result = await this.$http.get({
					url: this.$api.getSelectTechnicianOrder,
					data: {
						technicianEvaluationId: 2, //技师id
						status: 1 //订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款
					}
				});
				if (result.code == 200) {
					console.log('我的订单result.', result);
					this.list = result.data;
				} else {
					this.$sun.toast(result.message);
				}
			}, */

			async addressFn(tiem) {
				console.log(tiem.latitude, tiem.longitude)
				let latMap = Number(tiem.latitude)
				let lngMap = Number(tiem.longitude)
				//纬度
				//经度
				// var longitude = parseFloat(lngMap);
				uni.openLocation({
					latitude: latMap,
					longitude: lngMap,
					success: function() {
						console.log('success');
					}
				});
				// 百度地图经纬度转腾讯地图经纬度
				// var x_pi = 3.14159265358979324;
				// var x = parseFloat(latMap) - 0.0065;
				// var y = parseFloat(lngMap) - 0.006;
				// var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
				// var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
				// var lat = (z * Math.cos(theta)).toFixed(7);
				// var lng = (z * Math.sin(theta)).toFixed(7);
				// //定位地方名称
				// var name = tiem.merchantAddress;
				// const map = await this.$sun.openLocation({
				// 	//拿到上面的计算好的（百度经纬度转腾讯经纬度）经纬度 进行一个赋值
				// 	lat: latMap,
				// 	lng: lngMap,
				// 	name:tiem.merchantAddress, //名称
				// 	address: tiem.merchantAddress, //地址
				// 	key: 'SFABZ-WANWW-FISRY-3IGTF-HV7RE-YSFTI' //腾讯key
				// });
			},
			// 点击导航调用
			async addressFn(tiem) {
				console.log(JSON.stringify(tiem) + '导航========================')
				//纬度
				var latitude = parseFloat(tiem.latitude);
				//经度
				var longitude = parseFloat(tiem.longitude);
				// 百度地图经纬度转腾讯地图经纬度
				var x_pi = 3.14159265358979324;
				var x = parseFloat(tiem.latitude) - 0.0065;
				var y = parseFloat(tiem.longitude) - 0.006;
				var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
				var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
				var lat = (z * Math.cos(theta)).toFixed(7);
				var lng = (z * Math.sin(theta)).toFixed(7);
				//定位地方名称
				var name = tiem.store_name;
				console.log(Number(lat), Number(lng))
				uni.openLocation({
					latitude: Number(lat),
					longitude: Number(lng),
					success: function() {
						console.log('success');
					},
					fail: function(res) {
						console.log('success', res);
					},
				});
				// const map = await this.$sun.openLocation({
				// 	//拿到上面的计算好的（百度经纬度转腾讯经纬度）经纬度 进行一个赋值
				// 	lat: lat,
				// 	lng: lng,
				// 	name: tiem.city, //名称
				// 	address: tiem.address, //地址
				// 	key: wx.getStorageSync('system').tencentMapKey ? wx.getStorageSync('system')
				// 		.tencentMapKey : 'SFABZ-WANWW-FISRY-3IGTF-HV7RE-YSFTI' //腾讯key
				// });
			},
			// 我的订单_接口已改，但数据传值未改
			async upCallback(scroll) {
				let commentSign = this.tabList[this.currentIndex].commentSign;
				let status = commentSign || this.tabList[this.currentIndex].id == -1 ? '' : this.tabList[this
					.currentIndex].id;
				const result = await this.$http.get({
					url: this.$api.getSelectTechnicianOrder,
					data: {
						page: scroll.num,
						limit: 10,
						orderNumber: this.searchVal,
						technicianEvaluationId: wx.getStorageSync('technicianId'), //技师id
						status: this.tabList[this.currentIndex]
							.id //订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款
					}
				});
				if (result.code == 200) {

					console.log('result.data', result.data);
					// this.mescroll.endByPage(result.data.list.length, 1);
					this.mescroll.endByPage(result.data.list.length, this.$sun.pagingSum(result.data.count, 10));
					if (scroll.num == 1) this.list = [];
					this.list = this.list.concat(result.data.list);


					console.log('我的订单this.list', this.list, '测试分页总条数', result.data.count, this.$sun.pagingSum(result
						.data.count, 10));

				}
			},
			// 拒绝接单
			refuseOrders(orderInfo) {
				uni.showModal({
					// title: '提示',
					confirmColor: '#1890ff',
					content: '确定拒绝该订单吗?',
					success: async res => {
						// 确定
						if (res.confirm) {
							// this.updateOrders(id, 5);
							// 退款操作
							const result = await this.$http.post({
								url: this.$api.refund,
								data: {
									orderId: Number(orderInfo.id), //订单id
									status: Number(
										orderInfo.status
									), //（订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款）
									orderNumber: orderInfo.orderNumber,

									// 退款金额
									refundAmount: orderInfo.disbursements,
									siteId: uni.getStorageSync('siteId'),
									userId: String(uni.getStorageSync('userId')),
									disbursements: orderInfo.disbursements,
									refundProcess: 1,

									refund: '其他原因',
									// 退款凭证
									refundVoucher: '', //图片，最多九张用英文逗号隔开
									number: orderInfo.number,
									refundInstructions: '',


								}
							});
							if (result.code == 200) {
								this.$sun.toast('您已拒绝接单');
								this.getChange(5); //传入下标
							}

						}
						// 取消
						else {
							this.$sun.toast('点击了取消');
						}
					}
				});
			},
			// 订单修改状态
			// status，代表操作后的下一步状态
			async updateOrders(orderId, status) {
				uni.showLoading({
					title: '加载中'
				});
				this.$at.uniDoFunc({
					// 键名
					key: 'submit',
					success: async () => {
						//锁定
						this.$at.lockKey('submit');
						const result = await this.$http.put({
							url: this.$api.orderUpdate,
							data: {
								id: Number(orderId), //订单id
								status: Number(
									status) //（订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款）
							}
						});
						if (result.code == 200) {
							uni.hideLoading();
							// 拒绝接单
							if (status == 5) {
								this.$sun.toast('您已拒绝接单');
								this.getChange(5); //传入下标
							}
							// 同意接单
							if (status == 2) {
								this.$sun.toast('您已同意接单');
								this.getChange(2);
							}
							// 开始服务
							if (status == 3) {
								// this.$sun.toast('开始服务');
								this.getChange(3);
							}
							// 结束服务
							if (status == 4) {
								this.$sun.toast('您已完成该接单');
								this.getChange(4);
							}

							setTimeout(() => {
								this.$at.releaseKey('submit');
							}, 100);
						} else {
							uni.hideLoading();
							this.$at.releaseKey('submit');
							this.$sun.toast(result.message);
						}
					}
				});
			}
		}
	};
</script>

<style lang="less">
	// '服务时间'弹框样式
	.v-time-pop {
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		padding: 30rpx 0 20rpx;
		background-color: #fff;
		z-index: 999;

		.time-cls,
		.sel-time-cls,
		.none-time-cls {
			border-radius: 20rpx;
			margin-left: 20rpx;
			margin-bottom: 20rpx;
			width: calc(100% / 4 - 26px);
			padding: 20rpx 10rpx;
			color: #666;
		}

		.time-cls {
			border: 2rpx solid #e5e5e5;
			color: #666;
		}

		.sel-time-cls {
			border: 2rpx solid #1890ff;
			background: #1890ff;
			color: #f9fffe;
		}

		.none-time-cls {
			background: #e5e5e5;
			color: #c9c9c9;
		}
	}

	/* 隐藏“导航栏”滚动条 */
	scroll-view ::-webkit-scrollbar {
		display: none;
		width: 0;
		height: 0;
		color: transparent;
	}

	.uni-stat-tooltip {
		width: 160px;
	}

	.v-pop-freeze {
		background: #fff;
		width: 600rpx;
		border-radius: 20rpx;

		.v-title {
			width: 100%;
			text-align: center;
			border-bottom: 2rpx solid #e1e1e1;
			padding: 30rpx 0 20rpx;
			font-size: 30rpx;
			font-weight: bold;
		}

		.v-content {
			padding: 30rpx 0;
			text-align: center;
		}
	}

	page {
		background-color: #f7f7f7;
	}

	.order-page {
		.search-content {
			justify-content: center;
			display: flex;
			align-items: center;
			width: 700rpx;
			height: 88rpx;
			margin: 30rpx;
			background: #fff;
			border-radius: 84rpx;

			.search-img {
				width: 30rpx;
				height: 30rpx;
				margin-right: 20rpx;
				margin-left: 40rpx;
			}

			.icon_close {
				padding: 0rpx 15rpx;
				width: 36rpx;
				height: 36rpx;
				margin-right: 30rpx;
			}
		}

		.confirm-time {
			height: 90rpx;
			margin: 20rpx 80rpx;
			color: #fff;
			border-radius: 56rpx;
			background: linear-gradient(90deg, #1890ff 0%, #1890ff 100%);
		}

		// 订单卡片
		.card-cls {
			margin: 14rpx 22rpx;
			padding: 30rpx 20rpx;
			border-radius: 10rpx;
			background: #fff;

			.addClockImg {
				position: relative;

				.addClock {
					text-align: center;
					line-height: 40rpx;

					color: #fff;
					position: absolute;
					width: 80rpx;
					height: 40rpx;
					background-color: #1890FF;
					top: 0rpx;
				}
			}

			.v-stauts,
			.v-timeout-stauts {
				border-radius: 0rpx 80rpx 80rpx 0rpx;
				padding: 6rpx 20rpx;
				margin-left: -20rpx;
			}

			.v-stauts {
				color: #fa5;
				background: #fff5ea;
			}

			.v-timeout-stauts {
				color: #f56c6c;
				background: rgb(254, 240, 240);
			}

			.order-num {
				text {
					color: #757575;
				}

				view {
					display: inline-block;
					color: #999;
					padding: 4rpx 10rpx;
					border-radius: 8rpx;
					border: 2rpx solid #bfbfbf;
					margin: 0 22rpx;
				}
			}

			.stauts-cls {
				color: #fff;
				border-radius: 80rpx 0rpx 0rpx 80rpx;
				background: linear-gradient(0deg, #1890ff 0%, #1890ff 100%);
				width: 120rpx;
				height: 48rpx;
				margin-right: -20rpx;
			}

			.stauts-clsTime {
				color: #fff;
				padding: 0 15rpx;
				background: linear-gradient(0deg, #1890ff 0%, #1890ff 100%);
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				height: 48rpx;
				margin-right: -20rpx;
			}

			.order-img {
				width: 136rpx;
				height: 136rpx;
				border-radius: 20rpx;
				margin-right: 20rpx;
			}

			.appointment-time {
				color: #757575;
				margin: 14rpx 0;
			}

			.call-cls {
				border-radius: 50%;
				width: 56rpx;
				height: 56rpx;
				background-color: #1890FF;

				image {
					height: 32rpx;
				}
			}

			// 分割线
			.segmentation {
				color: #d0d0d0;
				margin: 0 18rpx;
			}

			.time-icon {
				color: #26c278;

				text {
					font-size: 28rpx;
				}

				view {
					margin-left: 8rpx;
				}
			}

			// 转单信息
			.transfer-cls {
				margin-top: 34rpx;

				image {
					border-radius: 50%;
					width: 48rpx;
					height: 48rpx;
					margin-right: 14rpx;
				}

				view {
					color: #26c278;
				}
			}

			// 虚线分割
			.dashed-line {
				margin: 28rpx 0;
				border-bottom: 2rpx dashed #e1e1e1;
			}

			.address-cls {
				text {
					font-size: 32rpx;
					color: #a1a1a1;
				}

				view {
					color: #757575;
					margin: 0 10rpx;
				}
			}

			.v-navigation {
				color: #09c680;

				image {
					padding-left: 10rpx;
					width: 38rpx;
					height: 38rpx;
				}
			}

			.service-btn {
				border-radius: 100rpx;
				background: #1890ff;
				margin: 38rpx 28rpx 0;
				height: 74rpx;
				color: #fff;
				font-weight: bold;
				font-size: 32rpx;
			}

			.big-btn {
				width: calc(70% - 20px) !important; // 判断是否转单，2是70-30
			}

			.agree-btn,
			.refuse-order,
			.zd-order {
				width: calc(100% / 3 - 20px); // 判断是否转单，2是70-30
				height: 74rpx;
				color: #fff;
				font-weight: bold;
				font-size: 32rpx;
				border-radius: 100rpx;
			}

			.refuse-order {
				color: #999;
				border: 2rpx solid #999;
				/* color: #f28331;
			border: 2rpx solid #fe7e01; */
				background: #fff;
			}

			.zd-order {
				background: #fff;
				border: 2rpx solid #67c23a;
				color: #67c23a;
			}

			.agree-btn {
				background: #1890ff;
				border: 2rpx solid #1890ff;
				color: #fff;
			}
		}
	}
</style>